package com.androidx.p013lv.base.model;

import android.content.Context;
import android.util.Log;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.androidx.p013lv.base.bean.AddTimesReq;
import com.androidx.p013lv.base.bean.DownLoadVideoNumBean;
import com.androidx.p013lv.base.bean.RelateVideoBean;
import com.androidx.p013lv.base.bean.ReqCollect;
import com.androidx.p013lv.base.bean.VideoBean;
import com.androidx.p013lv.base.bean.VideoHistory;
import com.androidx.p013lv.base.bean.request.ReqBuyVideo;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.JsonParams;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.utils.VideoHistoryUtils;
import com.google.gson.Gson;
import p023io.reactivex.android.schedulers.AndroidSchedulers;
import p023io.reactivex.disposables.CompositeDisposable;
import p023io.reactivex.functions.Action;
import p023io.reactivex.schedulers.Schedulers;

/* renamed from: com.androidx.lv.base.model.VideoPlayerModel */
public class VideoPlayerModel extends ViewModel {
    private MutableLiveData<BaseRes<Integer>> buyVideoData;
    private MutableLiveData<BaseRes<DownLoadVideoNumBean>> downLoadVideoNum;
    private MutableLiveData<BaseRes<RelateVideoBean>> guessLikeData;
    private MutableLiveData<BaseRes<RelateVideoBean>> relateData;
    private MutableLiveData<BaseRes> scoreData;
    private MutableLiveData<BaseRes<VideoBean>> videoLiveData;

    public MutableLiveData<BaseRes<Integer>> dataBuyVideo() {
        if (this.buyVideoData == null) {
            this.buyVideoData = new MutableLiveData<>();
        }
        return this.buyVideoData;
    }

    public MutableLiveData<BaseRes> dataScore() {
        if (this.scoreData == null) {
            this.scoreData = new MutableLiveData<>();
        }
        return this.scoreData;
    }

    public MutableLiveData<BaseRes<RelateVideoBean>> dataGuessLike() {
        if (this.guessLikeData == null) {
            this.guessLikeData = new MutableLiveData<>();
        }
        return this.guessLikeData;
    }

    public MutableLiveData<BaseRes<RelateVideoBean>> dataRelate() {
        if (this.relateData == null) {
            this.relateData = new MutableLiveData<>();
        }
        return this.relateData;
    }

    public MutableLiveData<BaseRes<VideoBean>> dataVideo() {
        if (this.videoLiveData == null) {
            this.videoLiveData = new MutableLiveData<>();
        }
        return this.videoLiveData;
    }

    public MutableLiveData<BaseRes<DownLoadVideoNumBean>> getDownLoadVideoData() {
        if (this.downLoadVideoNum == null) {
            this.downLoadVideoNum = new MutableLiveData<>();
        }
        return this.downLoadVideoNum;
    }

    public void getDownLoadVideoNum() {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getDownLoadNum(), new HttpCallback<BaseRes<DownLoadVideoNumBean>>("downLoadVideoNum") {
            /* class com.androidx.p013lv.base.model.VideoPlayerModel.C10381 */

            public void onLvSuccess(BaseRes<DownLoadVideoNumBean> baseRes) {
                VideoPlayerModel.this.downLoadVideoNum.setValue(baseRes);
            }
        });
    }

    public void getVideoById(int i, Context context) {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().videoById(i), new HttpCallback<BaseRes<VideoBean>>("videoById", context) {
            /* class com.androidx.p013lv.base.model.VideoPlayerModel.C10412 */

            public void onLvSuccess(BaseRes<VideoBean> baseRes) {
                VideoPlayerModel.this.videoLiveData.setValue(baseRes);
            }
        });
    }

    public void relatedVideo(int i) {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().relatedVideo(i), new HttpCallback<BaseRes<RelateVideoBean>>("relatedVideo") {
            /* class com.androidx.p013lv.base.model.VideoPlayerModel.C10423 */

            public void onLvSuccess(BaseRes<RelateVideoBean> baseRes) {
                VideoPlayerModel.this.relateData.setValue(baseRes);
            }
        });
    }

    public void guessLikeVideo(int i) {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().guessLikeVideoNew(i), new HttpCallback<BaseRes<RelateVideoBean>>("guessLikeVideo") {
            /* class com.androidx.p013lv.base.model.VideoPlayerModel.C10434 */

            public void onLvSuccess(BaseRes<RelateVideoBean> baseRes) {
                VideoPlayerModel.this.guessLikeData.setValue(baseRes);
            }
        });
    }

    public void likeVideo(int i) {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().likeVideo(), JsonParams.build().add(Key.VIDEO_ID, Integer.valueOf(i)).commit(), new HttpCallback<BaseRes>("likeVideo") {
            /* class com.androidx.p013lv.base.model.VideoPlayerModel.C10445 */

            public void onLvSuccess(BaseRes baseRes) {
            }
        });
    }

    public void unLikeVideo(int i) {
        String cancelVideoLike = UrlManager.getInsatance().cancelVideoLike();
        ReqCollect reqCollect = new ReqCollect();
        reqCollect.getVideoIds().add(Integer.valueOf(i));
        HttpUtils.getInsatance().post(cancelVideoLike, new Gson().toJson(reqCollect), new HttpCallback<BaseRes<String>>("cancelVideoLike") {
            /* class com.androidx.p013lv.base.model.VideoPlayerModel.C10456 */

            public void onLvSuccess(BaseRes<String> baseRes) {
            }
        });
    }

    public void buyOrLeaseVideo(int i, final int i2, boolean z, Context context) {
        String userBuyVideo = UrlManager.getInsatance().userBuyVideo();
        ReqBuyVideo reqBuyVideo = new ReqBuyVideo();
        reqBuyVideo.setPurType(i2);
        reqBuyVideo.setVideoId(i);
        reqBuyVideo.setBrush(z);
        reqBuyVideo.setTicketDeduct(false);
        HttpUtils.getInsatance().post(userBuyVideo, new Gson().toJson(reqBuyVideo), new HttpCallback<BaseRes<Integer>>("userBuyVideo", context) {
            /* class com.androidx.p013lv.base.model.VideoPlayerModel.C10467 */

            public void onLvSuccess(BaseRes<Integer> baseRes) {
                baseRes.setData(Integer.valueOf(i2));
                VideoPlayerModel.this.buyVideoData.setValue(baseRes);
            }
        });
    }

    public void userVideoScore(double d, int i) {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().userVideoScore(), JsonParams.build().add("score", Double.valueOf(d)).add(Key.VIDEO_ID, Integer.valueOf(i)).commit(), new HttpCallback<BaseRes>("userVideoScore") {
            /* class com.androidx.p013lv.base.model.VideoPlayerModel.C10478 */

            public void onLvSuccess(BaseRes baseRes) {
                VideoPlayerModel.this.scoreData.setValue(baseRes);
            }
        });
    }

    public void addStatisticsTimes(int i, int i2, int i3) {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().addStatisticsTimes(), new Gson().toJson(new AddTimesReq(i, i2, i3)), new HttpCallback<BaseRes>("addTimes") {
            /* class com.androidx.p013lv.base.model.VideoPlayerModel.C10489 */

            public void onLvSuccess(BaseRes baseRes) {
            }
        });
    }

    public void insertHistory(VideoBean videoBean, int i) {
        VideoHistory videoHistory = new VideoHistory(videoBean.getVideoId(), videoBean.getScore(), videoBean.getTitle(), videoBean.getPlayTime(), (videoBean.getCoverImg() == null || videoBean.getCoverImg().size() <= 0) ? "" : videoBean.getCoverImg().get(0), i, videoBean.getVideoType(), videoBean.isSelfMade());
        final CompositeDisposable compositeDisposable = new CompositeDisposable();
        compositeDisposable.add(VideoHistoryUtils.getInstance().insert(videoHistory).subscribeOn(Schedulers.m1118io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action() {
            /* class com.androidx.p013lv.base.model.VideoPlayerModel.C103910 */

            @Override // p023io.reactivex.functions.Action
            public void run() throws Exception {
                Log.e("---->", "add----ok");
                compositeDisposable.clear();
            }
        }));
    }

    public void recommendClick(String str, String str2) {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().recommendClick(str, str2), new HttpCallback<BaseRes>("recommendClick") {
            /* class com.androidx.p013lv.base.model.VideoPlayerModel.C104011 */

            public void onLvSuccess(BaseRes baseRes) {
            }
        });
    }

    public void cancelHttp() {
        HttpUtils.getInsatance().cancelTag("userVideoScore");
        HttpUtils.getInsatance().cancelTag("likeVideo");
        HttpUtils.getInsatance().cancelTag("cancelVideoLike");
        HttpUtils.getInsatance().cancelTag("videoById");
        HttpUtils.getInsatance().cancelTag("relatedVideo");
        HttpUtils.getInsatance().cancelTag("guessLikeVideo");
        HttpUtils.getInsatance().cancelTag("userBuyVideo");
        HttpUtils.getInsatance().cancelTag("addTimes");
        HttpUtils.getInsatance().cancelTag("recommendClick");
    }
}
